2
תגובות

PHP ZipArchive עם עברית

פתח DanielPHP ,

This code works properly to make the ZIP file with the wanted files, except the filenames in the archive, which are in hebrew, have weird characters instead of the proper hebrew letters.
Meaning, $filesfordown = $_POST['GEMin']; are all hebrew utf-8 filenames. They are added successfully, however when opening the ZIP the filenames are corrupted.


<?php
$filesfordown = $_POST['GEMin'];
    if(empty($filesfordown))
    {
        echo "No files were seleceted for download.";
    }
    else
    {
$zip_name = "RMW." . time() . ".zip";
$zip = new ZipArchive;
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($filesfordown as $filefordown) {
  $zip->addFile($filefordown);
}
$zip->close(); }

header('Content-Type: application/zip');
header("Content-disposition: attachment; filename='$zip_name'");
header('Content-Length: ' . filesize($zip_name));
readfile($zip_name);

ob_flush;
?>



I did some searching around, it seems that iconv, setlocalte, or mb_convert_encoding might help, but whatever I tried didn't work.

Any ideas?

2 תשובות

avatar ענה intval ב 16 לדצמבר 2013 #


It is a bug with php (see #53948)
The comments suggest to upgrade your php and phpArchive pecl versions to the latest available
or try working around by converting to dos encoding:

$zip->addFile($filefordown, iconv("UTF-8","CP852",$filefordown));

avatar ענה DanielPHP ב 16 לדצמבר 2013 #

I actually posted a fix myself. Same as yours, but with the correct CP. It should be CP862.
See my explanation here:
http://stackoverflow.com/questions/20600843/php-ziparchive-non-english-filenames-return-funky-filenames-within-archive